import pymysql

def main():
    no = int(input('要编辑的部门编号：'))
    loc = input('部门新地址：')
    # 获取数据库对象
    conn = pymysql.connect(
        host='localhost',
        port=3306,
        user='root',
        password='123456',
        db='hrs',
        charset='utf8mb4'

    )
    try:
        with conn.cursor() as cursor:
            result = cursor.execute(
                'update tb_dept set dloc = %s where dno = %s',(loc,no))
            if result == 1:
                print('更新成功')

            conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()

    finally:
        conn.close()


    print(conn)


if __name__ == '__main__':
    main()